home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr10 / rmast40.zip / DEMO5.C < prev    next >
C/C++ Source or Header  |  1994-01-12  |  2KB  |  103 lines

  1. /* ************************************************************* */
  2. /* demo5.c For Turbo C - Demonstrates how to set palettes        */
  3. /*                                                               */
  4. /*                                                               */
  5. /* Use the RM to create palette tables.                          */
  6. /*                                                               */
  7. /* NOTE: The BGI setrgbpalette function does not work properly.  */
  8. /*       Use the setrgb function that is provided here.          */
  9. /* ************************************************************* */
  10.  
  11. #include <stdio.h>
  12. #include <dos.h>
  13. #include <graphics.h>
  14.  
  15. int huge DetectVGA256(void)
  16. {
  17.  return(0);   /* change 0 to other value for SVGA modes */
  18. }
  19.  
  20. void setvga256(void)
  21. {
  22.  int gm,driver = DETECT;
  23.  installuserdriver("svga256",DetectVGA256);
  24.  initgraph(&driver,&gm,"");
  25. }
  26.  
  27. void setvga16()
  28. {
  29.  int driver = VGA,
  30.        mode = VGAHI;
  31.  
  32.  initgraph(&driver, &mode, "");
  33. }
  34.  
  35. void setrgb(int c, int r, int g, int b)
  36. {
  37.   union REGS reg;
  38.  
  39. if ((getmaxcolor()==15) && (c<16))
  40. {
  41.  reg.h.ah = 0x10;
  42.  reg.h.al = 0;
  43.  reg.h.bl = c;
  44.  reg.h.bh = c;
  45.  int86(0x10, ®, ®);
  46. }
  47.  reg.h.ah = 0x10;
  48.  reg.h.al = 0x10;
  49.  reg.x.bx = c;
  50.  reg.h.dh = r;
  51.  reg.h.ch = g;
  52.  reg.h.cl = b;
  53.  int86 (0x10, ®,®);
  54. }
  55.  
  56. void setnewpalette()
  57. {
  58.  /* C Palette Source, 16 Colors (RGB)  */
  59.  
  60.  char Pal[48] = {
  61.           0x00,0x00,0x00,0x3F,0x15,0x15,0x3F,0x18,0x18,0x3F,0x1B,0x1B,
  62.           0x3F,0x1E,0x1E,0x3F,0x21,0x21,0x3F,0x24,0x24,0x3F,0x27,0x27,
  63.           0x3F,0x2A,0x2A,0x3F,0x2D,0x2D,0x3F,0x30,0x30,0x3F,0x33,0x33,
  64.           0x3F,0x36,0x36,0x3F,0x39,0x39,0x3F,0x3C,0x3C,0x3F,0x3F,0x3F};
  65.  
  66.  int i;
  67.  for(i=0;i<16;i++)
  68.  {
  69.  setrgb(i,Pal[i*3],Pal[i*3+1],Pal[i*3+2]);
  70.  }
  71. }
  72.  
  73. void drawbars()
  74. {
  75.  int i;
  76.  int barwidth,barheight;
  77.  int numcolors;
  78.  
  79.  numcolors=getmaxcolor()+1;
  80.  barwidth=getmaxx() / numcolors;
  81.  barheight=getmaxy() / 2;
  82.  
  83.  for(i=0;i<numcolors;i++)
  84.  {
  85.    setfillstyle(SOLID_FILL,i);
  86.    bar(i*barwidth,0,i*barwidth+barwidth,barheight);
  87.  }
  88. }
  89.  
  90. void main()
  91. {
  92.   setvga16();          /* replace with setvga256 for 256 color palettes */
  93.  
  94.   drawbars();
  95.   getch();
  96.   setnewpalette();
  97.   setcolor(15);
  98.   outtextxy(getmaxx()/2-50,getmaxy()/2+50,"NEW PALETTE");
  99.  
  100.   getch();
  101.   closegraph();
  102. }
  103.